import { WS_CONNECT, WS_DISCONNECT } from '../middleware/ws'
import { APP_ACTION } from '../reducers/appReducer'
import { THEME } from '../../constants/constants'
import storageUtils from '../../utils/storageUtils'

/**
 * 改变主题
 * @returns {function(...[*]=)}
 */
export function changeTheme () {
  return (dispatch, getState) => {
    const theme = getState().app.get('theme') === THEME.NIGHT ? THEME.DAY : THEME.NIGHT
    storageUtils.saveValue(storageUtils.THEME, theme)
    dispatch({
      type: APP_ACTION,
      data: {
        theme
      }
    })
  }
}

/**
 * 连接ws
 * @returns {{data: {}, type: string}}
 */
export function connectWs () {
  return {
    type: WS_CONNECT
  }
}

/**
 * 断开ws连接
 * @returns {{data: {}, type: string}}
 */
export function disconnectWs () {
  return {
    type: WS_DISCONNECT
  }
}
